package com.gjintel.business.webadv.dao.Impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gjintel.business.webadv.dao.IWebAdvDao;
import com.gjintel.business.webadv.model.WebAdv;
import com.gjintel.sdk.base.dao.HibernateGenericDAO;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.base.dao.Sort;
import com.gjintel.sdk.util.StringUtil;


/**
 * @description 文章类型数据处理实现
 * @author Ant-K
 * @date 2016-3-16 下午19:38:39
 */

@Repository("WebAdvDao")
public class WebAdvDaoImpl extends HibernateGenericDAO implements IWebAdvDao{

	@SuppressWarnings("unchecked")
	public List<WebAdv> findAll() {
		String hql = "from WebAdv g where g.flag=0 order by g.createTime asc";
		return this.find(hql);
	}

	@SuppressWarnings("unchecked")
	public void findAll(Page page, WebAdv adv, Sort sort) {
		StringBuffer hql = new StringBuffer("from WebAdv g where g.flag=0");
		List params = new ArrayList(2); 
		if (adv != null) {
			if (!StringUtil.isEmpty(adv.getContent())) {
				hql.append(" and g.content like ? ");
				params.add("%" + adv.getContent().trim() + "%");
			}
			
			
			if (adv.getStartTime()!=null) {
				String str=adv.getStartTime().toString();
				hql.append(" and g.startTime >= ? ");
				params.add(adv.getStartTime());
			}
			
			if (adv.getEndTime()!=null) {
				hql.append(" and g.endTime <= ? ");
				params.add(adv.getEndTime());
			}
		}
		//hql.append(" order by g.dis_sort asc");
		this.findAsPage(hql.toString(), page, sort, "g", true, params.toArray());
	}
}
